<?php
include_once('lib/common.php');


class vmw_Home extends vmw_Page
{
    public function __construct($title = 'Virtual Machines')
    {
        parent::__construct($title);
    }


    protected function GetJQBody()
    {
        global $vmware;

        $content = '<ul data-role="listview">' . "\r\n";

        $hosts = $vmware->ListHosts(null, array('name', 'summary.overallStatus'));
        foreach ($hosts as $host)
        {
            $content .= '<li data-theme="b">' .
                ' <a href="host.php?host=' . urlencode($host->GetInstance()) . '">' . $host->properties['name'] .
                vic_Enum::ManagedEntityStatus($host->properties['summary.overallStatus'], vic_Enum::AS_IMAGE, array('class' => 'ui-li-icon')) . '</a></li>';

            $vms = $vmware->ListVirtualMachines($host, array('name', 'summary.runtime'));
            foreach ($vms as $vm)
            {
                $name = $vm->properties['name'];
                if ($vm->properties['summary.runtime']['powerState'] == 'poweredOn')
                    $icon = '<img class="ui-li-icon" src="images/play.png" alt="Powered On" />';
                else if ($vm->properties['summary.runtime']['powerState'] == 'poweredOff')
                    $icon = '<img class="ui-li-icon" src="images/stop.png" alt="Powered Off" />';
                else if ($vm->properties['summary.runtime']['powerState'] == 'suspended')
                    $icon = '<img class="ui-li-icon" src="images/pause.png" alt="Suspended" />';
                else
                    $icon = '';

                $content .= '<li><a href="vm.php?vm=' . urlencode($vm->GetInstance()) . '">' . $icon . $name . '</a></li>';
            }
        }

        $content .= '</ul>' . "\r\n";

        return $content;
    }
}

vmware_session();
$page = new vmw_Home();
$page->ProcessRequest();
?>
